
package com.kanjian.music.activity;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.ImageLoader.ImageListener;
import com.kanjian.music.KanjianApplication;
import com.kanjian.music.R;
import com.kanjian.music.api.ApiURL;
import com.kanjian.music.constants.SinaWeiboConstants.Constants;
import com.kanjian.music.download.MusicDownloadListener;
import com.kanjian.music.download.MusicDownloadTask;
import com.kanjian.music.download.MusicDownloader;
import com.kanjian.music.entity.Music;
import com.kanjian.music.volley.MultiPartRequest;
import com.kanjian.music.volley.VolleyQueue;
import com.sina.weibo.sdk.auth.Oauth2AccessToken;
import com.sina.weibo.sdk.auth.WeiboAuth;
import com.sina.weibo.sdk.auth.WeiboAuthListener;
import com.sina.weibo.sdk.auth.sso.SsoHandler;
import com.sina.weibo.sdk.exception.WeiboException;

/**
 * 关于我们页面
 * 
 * @author xuyanjun@kanjian.com
 */
public class AboutUsActivity extends BaseActivity {

    // http://img.plures.net/8b1f/dfa8/2d6f/f88b/fb49/1a4d/0eac/3590.jpg
    // http://img2.bdstatic.com/img/image/94877c6a7efce1b9d168036a02df1deb48f8d54648c.jpg

    static int i = 0;

    @Override
    protected void onCreate(Bundle arg0) {

        final String[] str = {
                "http://img.plures.net/8b1f/dfa8/2d6f/f88b/fb49/1a4d/0eac/3590.jpg",
                "http://img2.bdstatic.com/img/image/94877c6a7efce1b9d168036a02df1deb48f8d54648c.jpg",
                "http://img.plures.net/c328/72d9/2040/36f9/33a7/8997/e36e/ee3a.jpg",
                "http://img.plures.net/live/screenshots/16204/4.jpg",
                "http://img.plures.net/live/screenshots/15368/4.jpg",
                "http://img.plures.net/live/screenshots/15465/14.jpg",
                "http://img.plures.net/live/screenshots/15987/4.jpg",
                "http://img.plures.net/live/screenshots/15609/5.jpg",
                "http://img.plures.net/live/screenshots/15509/4.jpg",
                "http://img.plures.net/live/screenshots/15973/5.jpg",
                "http://img.plures.net/live/screenshots/16014/7.jpg",
                "http://img.plures.net/live/screenshots/16202/9.jpg",
                "http://img.plures.net/live/screenshots/16221/6.jpg",
                "http://img.baidu.com/img/image/3bf33a87e950352a5947ae485143fbf2b2.jpg",
                "http://e.hiphotos.baidu.com/image/w%3D2048/sign=7f1788f2d762853592e0d521a4d777c6/6d81800a19d8bc3e5572f4ca808ba61ea8d345bc.jpg",
                "http://e.hiphotos.baidu.com/image/w%3D2048/sign=df72f04fc88065387beaa313a3e5a044/77c6a7efce1b9d16b19bef60f1deb48f8c546456.jpg",
                "http://a.hiphotos.baidu.com/image/w%3D2048/sign=0d7c96f9a586c91708035539fd0571cf/0824ab18972bd407ad4ca1fc79899e510fb30923.jpg",
                "http://e.hiphotos.baidu.com/image/w%3D2048/sign=010f5aabd439b6004dce08b7dd68342a/b90e7bec54e736d13befd5409a504fc2d46269fd.jpg",
                "http://b.hiphotos.baidu.com/image/w%3D2048/sign=8d3654ee8fb1cb133e693b13e96c574e/f9dcd100baa1cd11cb154d21bb12c8fcc3ce2d0b.jpg",
                "http://g.hiphotos.baidu.com/image/w%3D2048/sign=8658b41dd62a283443a6310b6f8dc9ea/adaf2edda3cc7cd96b1190d93b01213fb80e91f6.jpg"
        };

        new Thread() {
            public void run() {
                HashMap<String, String> params = new HashMap<String, String>();
                if (KanjianApplication.SID != null) {
                    params.put("sid", KanjianApplication.SID);
                }
                Map<String, File> files = new HashMap<String, File>();
                files.put("pic_bin", new File("/mnt/sdcard/a.jpg"));
                try {
                    MultiPartRequest.post(ApiURL.spellUrl(ApiURL.URL_ACTION_CHANGE_AVATAR), params,
                            files);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            };
        }.start();

        setContentView(R.layout.activity_aboutus);
        super.onCreate(arg0);
        ImageView iv = (ImageView) findViewById(R.id.img);
        final ImageListener listener = ImageLoader.getImageListener(iv, R.drawable.ic_launcher,
                R.drawable.image_test);
        iv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // i = (i == str.length - 1) ? 0 : i + 1;
                // VolleyQueue.getImageLoader().get(str[i], listener);
                // mPlayService.play();
            }
        });

        // weibo test
        // WeiboAuth mWeiboAuth = new WeiboAuth(this, Constants.APP_KEY,
        // Constants.REDIRECT_URL,
        // Constants.SCOPE);
        //
        // SsoHandler mSsoHandler = new SsoHandler(AboutUsActivity.this,
        // mWeiboAuth);
        //
        // mSsoHandler.authorize(new AuthListener());
    }

    class AuthListener implements WeiboAuthListener {

        @Override
        public void onComplete(Bundle values) {
            Oauth2AccessToken mAccessToken = Oauth2AccessToken.parseAccessToken(values); // 从
            if (mAccessToken.isSessionValid()) {
                // AccessTokenKeeper.writeAccessToken(WBAuthActivity.this,
                // mAccessToken); //保存Token
                System.out.println(mAccessToken.getToken());
            } else {
                // 当您注册的应用程序签名不正确时,就会收到错误Code,请确保签名正确
                String code = values.getString("code");
            }
        }

        @Override
        public void onCancel() {
            // TODO Auto-generated method stub

        }

        @Override
        public void onWeiboException(WeiboException arg0) {
            // TODO Auto-generated method stub

        }
    }
}
